package fcrpt

import java.text.SimpleDateFormat

class UserWorkController {
    def commonDataService
    def dynamicQueryService
    def index(Integer max) {
        def cellList = org.kdx.DataUtils.getCellList()
        def pageSizeList = org.kdx.DataUtils.getPageSizeList()

        [totalCount: 5, pageSize: 20, pageCurrent: 1, orderField: 'id', orderDirection: 'asc', pageSizeList: pageSizeList, cellList: cellList]
    }


    def userWork(){

        println(123123123)
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        params.stepName=params.stepName
        params.state=params.state

        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime()-29))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date()))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)

        def tableHeadList=[]
        def userWork=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0

        def userWorkSumQty=[]
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'userWork'
            userWork = dynamicQueryService.queryForList(params)
            tableHeadList =  []
            if(userWork.size()>0){
                tableHeadList =  userWork[0].keySet()
            }
            params.SYS_QUERY_NAME = 'userWorkCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

            params.SYS_QUERY_NAME = 'userWorkSumQty'
            userWorkSumQty = dynamicQueryService.queryForList(params)

        }


        render(view:'userWork',model:[totalCount:totalCount,tableHeadList:tableHeadList,
                                      pageSizeList:pageSizeList,pageSize:pageSize,
                                      startno:params.startno?:'',endno:params.endno?:'',
                                      partName:params.partName?:'',userWork:userWork,
                                      stepName:params.stepName?:'',startTime:params.startTime?:'',endTime:params.endTime?:'',
                                      stepDesc:params.stepDesc?:'',userName:params.userName?:'',department:params.department?:'',
                                      lotId:params.lotId?:'',eqp:params.eqp?:'',user:params.user?:'',group3:params.group3?:''

                                      ,userWorkSumQty:userWorkSumQty
        ])

    }
}
